//-----------------Sonic CD Pause Menu Script-----------------//
//--------Scripted by Christian Whitehead 'The Taxman'--------//
//-------Unpacked By Rubberduckycooly's Script Unpacker-------//

// Aliases

// How long the Pause Menu should initially slide out for
private alias Object.PropertyValue : Object.ExtendTime

private alias Object.Value0 : Object.Timer

// The current highlighted selection, check out the PAUSEMENU_SEL_* aliases right down below
private alias Object.Value1 : Object.CurrentSelection

// Selection Aliases
private alias -1 : PAUSEMENU_SEL_NULL
private alias  0 : PAUSEMENU_SEL_CONTINUE
private alias  1 : PAUSEMENU_SEL_RESTART
private alias  2 : PAUSEMENU_SEL_EXIT
private alias  3 : PAUSEMENU_SEL_DEVMENU

// X Position of the underline that's underneat the Options texts
private alias Object.Value2 : Object.UnderlinePos

// X Position for the Black Bar behind the Pause Text
// This is accompanied by PauseBarYPos, check out below for more about Value4 since it's multi-use in this Object
private alias Object.Value3 : Object.PauseBarXPos

// Value4 has different uses across this Object's various States

// In states 0-2:
	// Value 4 is used to hold the Y Position of the White Rectangle
	private alias Object.Value4 : Object.WhiteRectPos
	
	// And then, this holds the position of that White Rectangle from the previous frame during those states
	// -> See ObjectDraw for more info
	private alias Object.Value5 : Object.PrevWhiteRectPos

// In states 4-5:
	// Value 4 is used to hold the Y Position of the Pause text & its bar
	// Check out PauseBarXPos too, though that one's just a normal Value and only has one use
	private alias Object.Value4 : Object.PauseBarYPos

// For clarity's sake, the two types of Value 4 uses are aliases differently

// Just a bool, essentially useless since restarts are always disabled in Special Stages so there's no reason for this to be here
// Check out its initial use for more info, but this Object's pretty much a copy of the Global version, where the variable *is* used for actual purpose
private alias Object.Value6 : Object.RestartDisabled

// Position of the stuff on the right side (options, black bar, etc.)
private alias Object.XPos : Object.SelectionBarPos

// values for the tiny 'lil sonic :)
private alias Object.Frame          : Object.SonicFrame
private alias Object.AnimationTimer : Object.SonicTimer

// States

// This Object can't have its value setup via a normal loop in ObjectStartup since it doesn't even exist
// normally - it's spawned in by the Sonic Object instead - so the first state is for initialising its values
private alias 0 : PAUSEMENU_INIT

// Once the Object is setup, all the shape parts of it slide in, including the white background, pause bar, and other black bar to the right
private alias 1 : PAUSEMENU_SLIDEIN

// After that, now the Sprite aspects of it fade in, like the Options and Pause text
private alias 2 : PAUSEMENU_FADEIN

// Yup, now we're in the main state!
// This is where all the good stuff is done, of course
private alias 3 : PAUSEMENU_MAIN

// Upon selecting any option, the selected option will flash for a few moments...
private alias 4 : PAUSEMENU_FLASH

// ... and after that comes a branch of fate - choose a path!

// If you selected the Continue option, then...
// Close the Pause Menu, and resume the normal game
private alias 5 : PAUSEMENU_CLOSE

// If you selected any other option, then...
// Make the Pause Menu consume the screen, and exit the level or whatever afterwards
private alias 6 : PAUSEMENU_EXIT

// One of the updates changed the left bounds for how far the Pause Menu should go
// Originally was -32, but the current version is -64
// That's about a two frames difference, isn't that interesting?
private alias -64 : PAUSEMENU_LEFTMOST

// Player Aliases
private alias 0 : PLAYER_SONIC_A
private alias 1 : PLAYER_TAILS_A

// Presentation Stages
private alias 0 : STAGE_P_TITLE
private alias 2 : STAGE_P_TIMEATTACK

// Languages
private alias 0 : LANG_ENGLISH
private alias 1 : LANG_FRENCH
private alias 2 : LANG_ITALIAN
private alias 3 : LANG_DEUTSCH
private alias 4 : LANG_SPANISH
private alias 5 : LANG_JAPANESE

// Screen Aliases
// This Object uses a hardcoded constant of 240 rather often, rather than Screen.YSize, so this is here just to clarify stuff a bit
private alias 240 : SCREEN_YSIZE

// Global SFX
private alias 23 : SFX_G_MENUBUTTON
private alias 27 : SFX_G_SELECT

// Ink Effect Aliases
private alias 2 : INK_ALPHA

// Game Mode Aliases
private alias 2 : MODE_TIMEATTACK

// Engine Messages
// (Strange to describe, but they're essentially system-level stuff that the engine transmits to the scripts)
private alias 2 : MESSAGE_LOSTFOCUS
private alias 3 : MESSAGE_YES_SELECTED
private alias 4 : MESSAGE_NO_SELECTED

// Engine Callbacks
private alias 6 : CALLBACK_RESTART_SELECTED
private alias 7 : CALLBACK_EXIT_SELECTED

// Tile Layer Types
private alias 4 : LAYER_3DSKY


event ObjectMain
	switch Object.State
	case PAUSEMENU_INIT
		// Object just got spawned, setup everything here
		StopSfx(SfxName[Fan3])
		StopSfx(SfxName[Phone])
		StopSfx(SfxName[Stare])
		PlaySfx(SfxName[Skidding], 0)
		// Start the right Bar to be, well, off to the right
		Object.SelectionBarPos = Screen.XSize
		
		// And then make the left Pause bar start all the way to the left
		Object.PauseBarXPos = 0
		
		Object.Timer = 0
		
		// The Object uses alpha effects to fade-in the test, so get that all set up too
		Object.InkEffect = INK_ALPHA
		Object.Alpha = 0
		
		// Some languages have longer text than others
		// LANG_FRENCH is the longest, while the standard LANG_ENGLISH version is the shortest
		switch Engine.Language
		case LANG_ENGLISH
		case LANG_JAPANESE
			Object.ExtendTime = 12
			break
			
		case LANG_FRENCH
			Object.ExtendTime = 15
			break
			
		// A bit of fall-through could probably be used on these last three entries, but it isn't
		// Oh well
		
		case LANG_ITALIAN
			Object.ExtendTime = 13
			break
			
		case LANG_DEUTSCH
			Object.ExtendTime = 13
			break
			
		case LANG_SPANISH
			Object.ExtendTime = 13
			break
			
		end switch

		Object.RestartDisabled = true

		Options.PhysicalControls = true

		
		Object.State++
		break
		
	case PAUSEMENU_SLIDEIN
		
		// Slide the Pause bar in
		Object.PauseBarXPos = Object.Timer
		Object.PauseBarXPos *= Screen.XSize
		Object.PauseBarXPos /= 12
		
		// And then move the background white rectangle in
		Object.WhiteRectPos = Object.Timer
		Object.WhiteRectPos *= SCREEN_YSIZE
		Object.WhiteRectPos /= 12
		
		// And then slide the right bar in too
		
		temp0 = Object.Timer
		temp0 <<= 7
		temp0 /= 12
		
		Object.SelectionBarPos = Screen.XSize
		Object.SelectionBarPos -= temp0
		
		if Object.Timer < Object.ExtendTime
			// Haven't reached where we should yet, keep moving...
			
			Object.Timer++
		else
			// Get ready to go to the next state
			
			// Setup the Underline initial position
			Object.UnderlinePos = Object.SelectionBarPos
			Object.UnderlinePos += 48
			
			Object.Timer = 0
			
			Object.State++
		end if
		break
		
	case PAUSEMENU_FADEIN
		if Object.Timer < 256
			Object.Timer += 16
			
			// Because Object.Alpha is a byte and will overflow if over 255,
			// we have to do this instead
			if Object.Timer < 255
				Object.Alpha = Object.Timer
			else
				Object.Alpha = 255
			end if
		else
			// Next state
			
			Object.Timer = 0
			
			// Just to make sure it's at full opacity
			Object.Alpha = 255
			
			Object.State++
		end if
		break
		
	case PAUSEMENU_MAIN

	// There's normally a `if Options.PhysicalControls == true` path here, but to keep 2012 Steam datafiles working we gotta do this roundabout way instead

		// Let's assume the variable doesn't exist, force Physical Controls
		CheckResult = true


		CheckEqual(Options.PhysicalControls, true)

		
		if CheckResult == true
			// Update Physical Controls
			
			if inputpress[0].Up == true
				
				PlaySfx(SfxName[Score Add], 0)	
				
				// Reset all the stuff
				
				Object.Timer = 0
				
				// Sonic should resume his normal stance
				Object.SonicTimer = 0
				Object.SonicFrame = 0
				
				// Move the bar all the way over to the right
				Object.UnderlinePos = Screen.XSize
				
				// And of course, bump down the current selection by one
				Object.CurrentSelection--
				
				// Enforce different upwards loop points based on if the 4th Dev Menu option is available or not
			
					if Object.CurrentSelection < PAUSEMENU_SEL_CONTINUE
						Object.CurrentSelection = PAUSEMENU_SEL_EXIT
					end if
			
				
				// If restart is disabled (which it always should be here) then don't let the player select it
				if Object.RestartDisabled == true
					if Object.CurrentSelection == PAUSEMENU_SEL_RESTART
						// Move them to the PAUSEMENU_SEL_CONTINUE instead
						Object.CurrentSelection--
					end if
				end if
				
			end if
			
			if inputpress[0].Down == true
				
				PlaySfx(SfxName[Score Add], 0)	
				
				// Reset some stuff
				
				Object.Timer = 0
				
				Object.SonicTimer = 0
				Object.SonicFrame = 0
				
				// Move the line back offscreen
				Object.UnderlinePos = Screen.XSize
				
				// And of course, move a selection down
				Object.CurrentSelection++
				
				// The Dev Menu adds a 4th entry, so the wrap around value is different too
			
					if Object.CurrentSelection > PAUSEMENU_SEL_EXIT
						Object.CurrentSelection = PAUSEMENU_SEL_CONTINUE
					end if
			
				
				// If restarting is disabled (always the case here in Special Stages) then
				// move the player's selection to PAUSEMENU_SEL_EXIT instead
				if Object.RestartDisabled == true
					if Object.CurrentSelection == PAUSEMENU_SEL_RESTART
						Object.CurrentSelection++
					end if
				end if
				
			end if
			
			// You can use either Start or A to close a selection, the other two buttons won't do anything though...
			if inputpress[0].Start == true
				PlaySfx(SfxName[Lamp Post], 0)
				Object.State = PAUSEMENU_FLASH
				Object.Alpha = 248
				Object.Timer = 0
			end if
			
			if inputpress[0].ButtonA == true
				PlaySfx(SfxName[Lamp Post], 0)
				Object.State = PAUSEMENU_FLASH
				Object.Alpha = 248
				Object.Timer = 0
			end if
			

			// If the Player's touched the screen at all, then switch to Touch Controls
			CheckTouchRect(0, 0, Screen.XSize, Screen.YSize)
			
			if CheckResult > -1
				Options.PhysicalControls = false
				Object.CurrentSelection = PAUSEMENU_SEL_NULL
			end if

		else
			
			// If the Player's not even in the game, then reset the current selection
		
			
			// From here, now we do a whole lotta stuff with touch controls, where we check manually for every option
			// For the most part, each chunk of code here is the same, only with one or two minor differences
			
			// See if the Player's tapped the screen at all, and store the result into temp3
			// This value is used throughout this entire touch controls section
			CheckTouchRect(0, 0, Screen.XSize, Screen.YSize)
			temp3 = CheckResult
			
			// And now, check for the Continue button
			
			// See if the Player's tapped it
			CheckTouchRect(temp0, 32, Screen.XSize, 64)
			
			if CheckResult > -1
				// If the player has their finger over the Continue button but hasn't relased it yet, then just keep it selected
				// but don't actually activate it yet
				
				Object.CurrentSelection = PAUSEMENU_SEL_CONTINUE
			else
				if temp3 < 0
					// The Player doesn't have their finger on the screen *nor* the Continue button
					
					if Object.CurrentSelection == PAUSEMENU_SEL_CONTINUE
						// The Player's released their finger while on the button, so let's start Continuing now
						
						PlaySfx(SfxName[Lamp Post], 0)
						Object.State = PAUSEMENU_FLASH
						Object.Alpha = 248
						Object.Timer = 0
					end if
				else
					// The Player's finger is on the screen but not on the Continue option, so make them deselect
					
					if Object.CurrentSelection == PAUSEMENU_SEL_CONTINUE
						Object.CurrentSelection = PAUSEMENU_SEL_NULL
					end if
				end if
			end if
			
			// Now, the Restart button
			// As said before, RestartDisabled is always gonna be true in a Special Stage so this whole chunk of code is essentially useless...
			
			// Yeah, I guess they just kept it here anyway because it looked cool or something idk
			if Object.RestartDisabled == false
				
				// See if the Player's got their finger over the Restart button
				CheckTouchRect(temp0, 80, Screen.XSize, 112)
				
				if CheckResult > -1
					// If they do, then make the current selection Restart
					
					Object.CurrentSelection = PAUSEMENU_SEL_RESTART
				else
					if temp3 < 0
						// The Player isn't touching the screen at all
						
						if Object.CurrentSelection == PAUSEMENU_SEL_RESTART
							// The Player released their finger while hovering over Restart, so let's restart then!
							
							PlaySfx(SfxName[Lamp Post], 0)
							Object.State = PAUSEMENU_FLASH
							Object.Alpha = 248
							Object.Timer = 0
						end if
					else
						// The finger has their player on the screen, but not over the Continue button
						
						if Object.CurrentSelection == PAUSEMENU_SEL_RESTART
							Object.CurrentSelection = PAUSEMENU_SEL_NULL
						end if
					end if
				end if
				
			end if
			
			// After that comes the wonderful, Exit button!
			
			// See if there's a finger on it
			CheckTouchRect(temp0, 80, Screen.XSize, 112)
			
			if CheckResult > -1
				// If there is, then make it the current selection
				
				Object.CurrentSelection = PAUSEMENU_SEL_EXIT
			else
				// The Player isn't currently on the Exit button
				
				if temp3 < 0
					// And, the Player isn't touching the screen at all!
					
					if Object.CurrentSelection == PAUSEMENU_SEL_EXIT
						// So in that case, if they were on it for at least one frame before, then let's go ahead and Exit
						
						PlaySfx(SfxName[Lamp Post], 0)
						Object.State = PAUSEMENU_FLASH
						Object.Alpha = 248
						Object.Timer = 0
					end if
				else
					// The Player's finger is on the screen, but not on the Exit button
					
					if Object.CurrentSelection == PAUSEMENU_SEL_EXIT
						Object.CurrentSelection = PAUSEMENU_SEL_NULL
					end if
				end if
			end if
			
			// Yup, and now the Dev Menu button!
			// It only shows under the most special conditions, they say...
			
	
			
			// And now, after all that's done, check for actual, physical inputs
			
			if inputpress[0].Up == true
				
				// If Up was pressed, then go to the bottommost entry
				// This'll vary if the Dev Menu is active, of course
				
			
					Object.CurrentSelection = PAUSEMENU_SEL_EXIT
			
				

				// And set Physical Controls to active, now that the player's actually pressed something
				
				Options.PhysicalControls = true

			end if
			
			if inputpress[0].Down == true
				
				// If Down was pressed, then just go to the topmost entry
				// Nothing further needed here
				
				Object.CurrentSelection = PAUSEMENU_SEL_CONTINUE
				

				// And similarly, set Physical Controls to be active for the same reason as before
				
				Options.PhysicalControls = true

			end if
		end if
		
		// Progress mini Sonic's animation
		
		if Object.Timer < 60
			// Make him stand all nice and polite for a second...
			
			Object.Timer++
		else
			// But once that second's over, gotta get moving!
			
			// Get the topmost bit of Sonic's Animation Timer
			Object.SonicFrame = Object.SonicTimer
			Object.SonicFrame >>= 4
			
			// And then bump it up one more to match with the Sprite Frame IDs
			Object.SonicFrame++
			
			Object.SonicTimer++
			Object.SonicTimer &= 31
		end if
		break
		
	case PAUSEMENU_FLASH
		
		// In this state, the Timer is used to control the selected sprite's visibility, or flashing
		// So, let's progress that value
		Object.Timer++
		Object.Timer &= 3
		
		// Slide the underline text away
		Object.UnderlinePos += 4
		
		// First, fade the texts out
		if Object.Alpha > 0
			Object.Alpha -= 8
		else
			if Object.CurrentSelection == PAUSEMENU_SEL_CONTINUE
				// If on the Continue option, then make the Pause Menu move away rather than cover the screen
				
				Object.UnderlinePos = Object.SelectionBarPos
				Object.UnderlinePos += 48
				
				// Set the initial Y position for the bottom bar
				// -> Normally, during the rest of the Pause Menu states, it's a direct constant 202,
				//    rather than reading from a variable, which is why the new variable is initially being set here
				Object.PauseBarYPos = 202
				
				Object.Timer = 0
				Object.Alpha = 128
				
				Object.State = PAUSEMENU_CLOSE
				
				// Resume the stage now, rather than when the Pause Menu is fully out of the way

				CheckEqual(object[26].state, 1)
				temp1 = checkResult
				CheckEqual(object[19].state, 1)
				temp1 |= checkResult
				CheckEqual(object[21].state, 1)
				temp1 |= checkResult				
				CheckEqual(object[25].state, 1)
				temp1 |= checkResult							
				if temp1 == 1
					StopSfx(SfxName[Stare])
				end if

				Stage.State = STAGE_RUNNING
			else
				
				// The following code is dependant on the current platform
				// Origins uses the Standard platform code, of course

				Object.UnderlinePos = Object.SelectionBarPos
				Object.UnderlinePos += 48
				StopMusic()
				Object.State = PAUSEMENU_EXIT

				

			end if
		end if
		break
		
	case PAUSEMENU_CLOSE
		if Object.Alpha > 0
			// Closing the Pause Menu...
			
			// Fade out the text
			Object.Alpha -= 8
			
			// And move all the other shapes out of the way
			Object.SelectionBarPos += 16
			Object.UnderlinePos += 16
			Object.PauseBarYPos += 16
			
		else
			// The Objects are already moving now, let's continue the music too!
			ResumeMusic()

			if OfficePower > 0
				PlaySfx(SfxName[Fan3], 1)
			end if
			
			// Erase this current Pause Menu Object, as it's no longer needed
			ResetObjectEntity(Object.entityPos, TypeName[Blank Object], 0, 0, 0)
			

			
		end if
		break
		
	case PAUSEMENU_EXIT
		if Object.SelectionBarPos > PAUSEMENU_LEFTMOST
			// Not arrived at the destination yet, keep on moving
			
			Object.SelectionBarPos -= 16
			Object.UnderlinePos += 16
		else
			
			// From here, jump to the handling needed
			
			switch Object.CurrentSelection
			case PAUSEMENU_SEL_RESTART
				// You should never be able to restart a Special Stage, so this piece of code goes unused...
				
	
				Player.Lives--
				
				LoadStage()
				break
				
			case PAUSEMENU_SEL_EXIT
				// Before Exiting, reset everything for the next playthrough
				

				
				stage.activeList = BONUS_STAGE
				stage.listPos = 3
				LoadStage()	
				
				break
				
			case PAUSEMENU_SEL_DEVMENU
				// To get to the Dev Menu, we need to reset the entire game rather than directly opening the menu or anything like that
				Engine.State = RESET_GAME
				break
				
			end switch
		end if
		break
		
	end switch
	
end event


event ObjectDraw
	switch Object.State
	case PAUSEMENU_INIT
	case PAUSEMENU_SLIDEIN
	case PAUSEMENU_FADEIN
		
		// Draw the White Rectangle Background
		
		// Don't draw it if it's at the bottom of the screen already
		if Object.PrevWhiteRectPos < SCREEN_YSIZE
			if Object.WhiteRectPos > Object.PrevWhiteRectPos
				
				// Note that the Stage State is currently paused, in other words nothing is getting rendered
				// -> That means that, if we were to simply draw a white tint rectangle from 0,0 to whereever,
				//    it would overlap with what was drawn the previous frame, and that would continously stack
				// -> Because of that, we have to not draw the entire tint rect at once, but
				//    draw only the difference from the previous frame every time instead
				
				// Find how tall the tint rectangle should be
				temp0 = Object.WhiteRectPos
				temp0 -= Object.PrevWhiteRectPos
				
				// Now, draw it at the previous rect position with the height found from earlier
				DrawRect(0, Object.PrevWhiteRectPos, 384, temp0, 255, 255, 255, 128)
				Object.PrevWhiteRectPos = Object.WhiteRectPos
				
			end if
		end if
		
		// Fall through to the next part
		// Note - Originally, there was a whole identical duplicate of the below code here, but Origins actually cleaned it up
		//        and made it easier for our eyes! How nice of them!
		
	case PAUSEMENU_MAIN
		
		// First, draw all the waves on the right
		DrawSpriteScreenXY(3, Object.SelectionBarPos, 0)
		DrawSpriteScreenXY(3, Object.SelectionBarPos, 32)
		DrawSpriteScreenXY(3, Object.SelectionBarPos, 64)
		DrawSpriteScreenXY(3, Object.SelectionBarPos, 96)
		DrawSpriteScreenXY(3, Object.SelectionBarPos, 128)
		DrawSpriteScreenXY(3, Object.SelectionBarPos, 160)
		DrawSpriteScreenXY(3, Object.SelectionBarPos, 192)
		DrawSpriteScreenXY(3, Object.SelectionBarPos, 224)
		
		// Draw the black rectangle on top of them too
		temp0 = Object.SelectionBarPos
		temp0 += 128
		DrawRect(temp0, 0, 128, Screen.YSize, 0, 0, 0, 255)
		
		// Draw the Pause bar
		DrawRect(0, 202, Object.PauseBarXPos, 13, 0, 0, 0, 255)
		DrawSpriteScreenFX(4, FX_INK, 0, 202)
		
		// Update Underline scrolling
		
		temp0 = Object.SelectionBarPos
		temp0 += 48
		
		if Object.UnderlinePos > temp0
			temp1 = temp0
			temp1 -= Object.UnderlinePos
			temp1 >>= 3
			
			// Move the unedrline to the left
			Object.UnderlinePos += temp1
		end if
		
		// Draw the Continue text
		
		temp1 = 48
		DrawSpriteScreenFX(6, FX_INK, temp0, temp1)
		
		if Object.CurrentSelection == PAUSEMENU_SEL_CONTINUE
			// If it's the current selection, then draw the underline and mini Sonic next to it
			
			DrawSpriteScreenFX(5, FX_INK, Object.UnderlinePos, temp1)
			DrawSpriteScreenFX(Object.SonicFrame, FX_INK, temp0, temp1)
		end if
		
		
		// Now, move to the Exit text position
		temp1 += 48
		
		// Draw the Exit text
		DrawSpriteScreenFX(8, FX_INK, temp0, temp1)
		
		if Object.CurrentSelection == PAUSEMENU_SEL_EXIT
			// If Exit is currently selected, then draw the underline and Sonic along with with
			
			DrawSpriteScreenFX(5, FX_INK, Object.UnderlinePos, temp1)
			DrawSpriteScreenFX(Object.SonicFrame, FX_INK, temp0, temp1)
		end if
		
		// Last but certainly not least, move to the Dev Menu text pos
		temp1 += 48
		
	
		break
		
	case PAUSEMENU_FLASH
		
		// Draw all the Bars
		DrawSpriteScreenXY(3, Object.SelectionBarPos, 0)
		DrawSpriteScreenXY(3, Object.SelectionBarPos, 32)
		DrawSpriteScreenXY(3, Object.SelectionBarPos, 64)
		DrawSpriteScreenXY(3, Object.SelectionBarPos, 96)
		DrawSpriteScreenXY(3, Object.SelectionBarPos, 128)
		DrawSpriteScreenXY(3, Object.SelectionBarPos, 160)
		DrawSpriteScreenXY(3, Object.SelectionBarPos, 192)
		DrawSpriteScreenXY(3, Object.SelectionBarPos, 224)
		
		// And a black rectangle on top of those bars
		temp0 = Object.SelectionBarPos
		temp0 += 128
		DrawRect(temp0, 0, 128, Screen.YSize, 0, 0, 0, 255)
		
		// Then, draw the Pause text bar
		DrawRect(0, 202, Object.PauseBarXPos, 13, 0, 0, 0, 255)
		DrawSpriteScreenXY(4, 0, 202)
		
		// Get the X Positions for the texts
		temp0 = Object.SelectionBarPos
		temp0 += 48
		
		// And now, the Y position for the Continue text
		temp1 = 48
		
		if Object.CurrentSelection == PAUSEMENU_SEL_CONTINUE
			
			// Draw the Continue text, but only every other second frame
			if Object.Timer < 2
				DrawSpriteScreenXY(6, temp0, temp1)
			end if
			
			// And then of course, the underline and Sonic come after
			DrawSpriteScreenXY(5, Object.UnderlinePos, temp1)
			DrawSpriteScreenXY(Object.SonicFrame, temp0, temp1)
			
		else
			// Nothing special to do here, just draw the Continue text with a fade out effect
			
			DrawSpriteScreenFX(6, FX_INK, temp0, temp1)
		end if
	
		
		// After that comes the Exit text
		temp1 += 48
		
		if Object.CurrentSelection == PAUSEMENU_SEL_EXIT
			
			// Flash it as needed
			if Object.Timer < 2
				DrawSpriteScreenXY(8, temp0, temp1)
			end if
			
			// And then, as with all the others, draw the underline and Sonic too
			DrawSpriteScreenXY(5, Object.UnderlinePos, temp1)
			DrawSpriteScreenXY(Object.SonicFrame, temp0, temp1)
			
		else
			// The player didn't choose to exit, so fade out the Exit text
			DrawSpriteScreenFX(8, FX_INK, temp0, temp1)
		end if
		
		// And then, the elusive Dev Menu
		temp1 += 48

		break
		
	case PAUSEMENU_CLOSE
		// This is the state where the Pause Menu is leaving the screen, after the player chose to resume the game
		
		if Object.Alpha < 128
			// Draw the white fade-in rectangle, around the entire screen
			
			// The stage is resumed now, meaning it's drawing again, which is why
			//  we can do the entire screen at once rather than the old `only difference` system needed before
			
			DrawRect(0, 0, Screen.XSize, SCREEN_YSIZE, 255, 255, 255, Object.Alpha)
		end if
		
		// On top of that fade rectangle, draw the Pause Menu
		
		// First, all the waves
		DrawSpriteScreenXY(3, Object.SelectionBarPos, 0)
		DrawSpriteScreenXY(3, Object.SelectionBarPos, 32)
		DrawSpriteScreenXY(3, Object.SelectionBarPos, 64)
		DrawSpriteScreenXY(3, Object.SelectionBarPos, 96)
		DrawSpriteScreenXY(3, Object.SelectionBarPos, 128)
		DrawSpriteScreenXY(3, Object.SelectionBarPos, 160)
		DrawSpriteScreenXY(3, Object.SelectionBarPos, 192)
		DrawSpriteScreenXY(3, Object.SelectionBarPos, 224)
		
		// Then, draw the black rectangle on the right
		temp0 = Object.SelectionBarPos
		temp0 += 128
		DrawRect(temp0, 0, 128, Screen.YSize, 0, 0, 0, 255)
		
		// Draw the Pause text's Bar
		DrawRect(0, Object.PauseBarYPos, Screen.XSize, 13, 0, 0, 0, 255)
		
		// And then, draw the actual Pause text on top of that
		DrawSpriteScreenXY(4, 0, Object.PauseBarYPos)
		
		// From here, the only text drawn is that of the current selection
		// So, jump as needed
		switch Object.CurrentSelection
		case PAUSEMENU_SEL_CONTINUE
			DrawSpriteScreenXY(6, Object.UnderlinePos, 48)
			DrawSpriteScreenXY(Object.SonicFrame, Object.UnderlinePos, 48)
			break
		
		case PAUSEMENU_SEL_EXIT
			DrawSpriteScreenXY(8, Object.UnderlinePos, 96)
			DrawSpriteScreenXY(Object.SonicFrame, Object.UnderlinePos, 96)
			break
			
		case PAUSEMENU_SEL_DEVMENU
		
			break
			
		end switch
		break
		
	case PAUSEMENU_EXIT
		// This is the state where the Pause Menu envelopes the screen, after choosing an option that isn't Continue
		
		// Black out the right side of the screen
		temp0 = Screen.XSize
		temp0 -= 96
		DrawRect(temp0, 0, 96, SCREEN_YSIZE, 0, 0, 0, 255)
		
		// Now, draw all the waves
		DrawSpriteScreenXY(3, Object.SelectionBarPos, 0)
		DrawSpriteScreenXY(3, Object.SelectionBarPos, 32)
		DrawSpriteScreenXY(3, Object.SelectionBarPos, 64)
		DrawSpriteScreenXY(3, Object.SelectionBarPos, 96)
		DrawSpriteScreenXY(3, Object.SelectionBarPos, 128)
		DrawSpriteScreenXY(3, Object.SelectionBarPos, 160)
		DrawSpriteScreenXY(3, Object.SelectionBarPos, 192)
		DrawSpriteScreenXY(3, Object.SelectionBarPos, 224)
		
		// And the black rectangle ontop of them, since it's sweeping left
		temp0 = Object.SelectionBarPos
		temp0 += 128
		DrawRect(temp0, 0, 128, Screen.YSize, 0, 0, 0, 255)
		
		// Draw the option selected and its underline as well, sliding to the right
		switch Object.CurrentSelection
		case PAUSEMENU_SEL_CONTINUE
			DrawSpriteScreenXY(6, Object.UnderlinePos, 48)
			DrawSpriteScreenXY(Object.SonicFrame, Object.UnderlinePos, 48)
			break
		case PAUSEMENU_SEL_EXIT
			DrawSpriteScreenXY(8, Object.UnderlinePos, 96)
			DrawSpriteScreenXY(Object.SonicFrame, Object.UnderlinePos, 96)
			break
			
		case PAUSEMENU_SEL_DEVMENU
		
			break
			
		end switch
		break
		
	end switch
	
end event


event ObjectStartup
	
	// Load the correct sprites for each language
	switch Engine.Language
	case LANG_ENGLISH
	case LANG_JAPANESE
		LoadSpriteSheet("FNAF/ScoreScreen.gif")
		break
	end switch


		// 0 - Standing Sonic
		SpriteFrame(-28, -14, 16, 24, 1, 231)
		// 1-2 - Impatient Sonic
		SpriteFrame(-28, -14, 16, 24, 18, 231)
		SpriteFrame(-28, -14, 16, 24, 35, 231)

	// 3 - Wave
	SpriteFrame(0, 0, 128, 32, 0, 128)
	
	// 4 - Pause Header
	SpriteFrame(0, -19, 128, 32, 0, 160)
	
	// 5 - Underline
	SpriteFrame(-6, 7, 128, 3, 0, 193)
	

		
		// 6 - Continue
		SpriteFrame(0, -5, 65, 11, 0, 197)
		
		// 7 - Restart
		SpriteFrame(0, -5, 55, 11, 66, 197)
		
		// 8 - Exit
		SpriteFrame(0, -5, 30, 11, 0, 209)
		
		// 9 - Dev Menu
		SpriteFrame(0, -5, 64, 11, 31, 209)
		
		// 10 - Greyed out Restart
		SpriteFrame(0, -5, 55, 11, 52, 244)
	
end event


// ========================
// Editor events
// ========================

event RSDKDraw
	DrawSprite(0)
end event


event RSDKLoad
	LoadSpriteSheet("3D_Test/ScoreScreen.gif")
	SpriteFrame(-64, -16, 128, 32, 0, 160)

	SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
end event
